/**
 * All rights Reserved, Designed By OprCalf
 * Copyright:    Copyright(C) 2016-2020
 * Company       BSL Ltd.
 */

package com.boots.atomikos.common.utils;

import org.jasypt.util.text.AES256TextEncryptor;

/**
 * 敏感信息加密工具类
 * @author：林溪
 * @date：2020年11月16日
 */

public class JasyptUtils {

    /**
     * 根据密码对加密值进行解密
     * @author OprCalf
     * @param decryptPsw 待解密的密码
     * @param decryptValue 待解密的值
     * @return String
     */
    public static String decryptMsg(String decryptPsw, String decryptValue) {
        final AES256TextEncryptor encryptor = new AES256TextEncryptor();
        encryptor.setPassword(decryptPsw);
        return encryptor.decrypt(decryptValue);
    }

    /**
     * 根据密码对加密值进行加密
     * @author OprCalf
     * @param decryptPsw
     * @param decryptValue
     * @return String
     */
    public static String encryptMsg(String decryptPsw, String decryptValue) {
        final AES256TextEncryptor encryptor = new AES256TextEncryptor();
        encryptor.setPassword(decryptPsw);
        return encryptor.encrypt(decryptValue);
    }

    public static void main(String args[]) {
        final String devPsw = "yx98ny34r9n2y43zn98rny324-9rtn3z4y328t";
        final String testPsw = "yn98cryb98y4bcr9n2u49crnu43x";
        final String proPsw = "bx7ry9urb023txbr09nu240rbynxu";
        System.out.println(encryptMsg(devPsw, "123456"));
        System.out.println(encryptMsg(devPsw, "BSLMDM2016"));
        System.out.println(encryptMsg(devPsw, "Bsl@123456"));
        System.out.println(encryptMsg(testPsw, "bsm@123456"));
        System.out.println(encryptMsg(testPsw, "BSLMDM2016"));
        System.out.println(encryptMsg(proPsw, "Bslerpdb_123"));
        System.out.println(encryptMsg(proPsw, "BSLMDM2016"));
    }

}
